<!--
 * @Author: 黑白灰01 3193273703@qq.com
 * @Date: 2025-01-27 10:57:57
 * @LastEditors: 黑白灰01 3193273703@qq.com
 * @LastEditTime: 2025-01-31 14:33:35
 * @FilePath: /hei_picture_web/src/page/home/HomeIndex.vue
 * @Description: 首页
-->
<template>
  <div>
    <PictureList :dataList="pictureList" :loading="loading" />
    <!-- 分页 -->
    <a-pagination
      class="pagination"
      v-model:current="searchParams.current"
      v-model:page-size="searchParams.pageSize"
      :page-size-options="pageSizeOptions"
      :total="total"
      :show-total="(total: number) => `共 ${total} 张图片`"
      show-size-changer
      @showSizeChange="onShowSizeChange"
    />
  </div>
</template>

<script setup lang="ts">
import { listPictureVoByPageUsingPost } from '@/api/pictureController'
import { onMounted, reactive, ref } from 'vue'
import PictureList from './modal/PictureList.vue'

// 搜索条件
const searchParams = reactive<API.PictureQueryRequest>({
  current: 1,
  pageSize: 12,
  sortField: 'createTime',
  sortOrder: 'descend',
})

const pictureList = ref<API.PictureVO[]>([])
const loading = ref<boolean>(false)
const total = ref<number>(0)
const fetchData = async () => {
  loading.value = true
  const res = await listPictureVoByPageUsingPost(searchParams)
  pictureList.value = res.data?.data?.records ?? []
  total.value = res.data?.data?.total ?? 0
  loading.value = false
}
const pageSizeOptions = ['12', '24']
const onShowSizeChange = (page: number, pageSize: number) => {
  searchParams.current = page
  searchParams.pageSize = pageSize
  fetchData()
}

onMounted(() => {
  fetchData()
})
</script>

<style scoped lang="scss">
.pagination {
  margin-top: 16px;
  margin-bottom: 16px;
  float: right;
}
</style>
